<?php
/**
 * User: wanghousheng
 * Date: 2017/8/22
 * Time: 11:00
 */
namespace Xiaoc\Common;
class Request extends \PhalApi\Request {
    public function getService() {
        // 优先返回自定义格式的接口服务名称
        $service = $this->get('r');
        if (!empty($service)) {
            $namespace = count(explode('/', $service)) == 2 ? 'Xiaoc.' : '';
            return $namespace . str_replace('/', '.', $service);exit();
        }else if(empty($_REQUEST['service']) && empty($_REQUEST['s'])){
            $url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            if (strstr($url,'?',true))$url = trim(strstr($url,'?',true),'/');
            $arr = explode('/', $url);
            array_shift($arr);
            if (!isset($arr[1]))$arr[1] = 'index';
            $namespace = count($arr) == 2 ? 'Xiaoc.' : '';
            return $namespace . str_replace('/', '.', implode('/',$arr));exit();
        }
        return parent::getService();

    }
}